const express=require('express')
const router= express.Router();
const db=require('../../utils/db')

router.get('/getsmallprogram', function(req, res, next) {
    let mysql = `SELECT customer_id,customer_name,customer_time,COUNT(customer_id) AS cx_amount,SUM(order_information.order_allprice) AS cx_money ,SUM(order_information.order_refund_money) AS cx_refund FROM customer JOIN order_information ON customer.customer_id=order_information.order_username GROUP BY customer_id`
    db(mysql, null, function(err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: '查询订单信息失败，请稍后重试'
            })
        }
        res.json({
            code: 200,
            msg: '查询订单信息成功',
            data: data
        })
    })
});
//模糊查询订单
router.get('/getsmallprogramid',function(req,res){
    let mysql=`SELECT * FROM (SELECT customer_id,customer_name,customer_time,COUNT(customer_id) AS cx_amount,SUM(order_information.order_allprice) AS cx_money ,SUM(order_information.order_refund_money) AS cx_refund FROM customer JOIN order_information ON customer.customer_id=order_information.order_username GROUP BY customer_id )AS t1 WHERE customer_time BETWEEN '${req.query.customer_time[0]}' AND '${req.query.customer_time[1]}'`
    db(mysql,null,function(err,data){
        if(err){
            return res.json({
                code: 500,
                msg: '模糊查询订单失败，请稍后重试'
            })
        }
        res.json({
            code: 200,
            msg: '模糊查询订单成功',
            data: data
        })
    })
})
module.exports = router